﻿using System;
using RpcHelper;
using SqlExecHelper;
using SqlExecHelper.SetColumn;
using Wedonek.RpcStore.Service.Model;

namespace Wedonek.RpcStore.Service.DAL
{
        internal class AutoTaskItemDAL : SqlBasicClass
        {
                public AutoTaskItemDAL () : base ("AutoTaskItem", "RpcExtendService")
                {

                }

                public Guid Add (AutoTaskItem item)
                {
                        item.Id = Tools.NewGuid ();
                        base.Insert (item);
                        return item.Id;
                }
                public AutoTaskItem Get(Guid id)
                {
                        return base.GetRow<Guid, AutoTaskItem> ("Id", id);
                }

                public TaskItem[] Gets(Guid taskId)
                {
                        return base.Get<Guid, TaskItem> ("TaskId", taskId);
                }
                public void Set (Guid id, SetTaskItem item)
                {
                        if (!base.Update (item, "Id", id))
                        {
                                throw new ErrorException ("rpc.task.item.set.fail");
                        }
                }

                internal void SetIsEnable (Guid id, bool isEnable)
                {
                        if (!base.Update (new ISqlSetColumn[] {
                                new SqlSetColumn("IsEnable", System.Data.SqlDbType.Bit){ Value=isEnable}
                        }, "Id", id))
                        {
                                throw new ErrorException ("rpc.task.item.set.fail");
                        }
                }

                public void Delete(Guid id)
                {
                        if (!base.Drop ("Id", id))
                        {
                                throw new ErrorException ("rpc.task.drop.fail");
                        }
                }

                internal TaskItemTitle[] GetTitles (Guid[] ids)
                {
                        return base.Get<Guid, TaskItemTitle> ("Id", ids);
                }
        }
}
